package com.gxa.service.asset.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.asset.Equipment;
import com.gxa.entity.asset.search.EquipmentSearchMap;
import com.gxa.service.asset.EquipmentService;
import com.gxa.mapper.asset.EquipmentMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
* @author Administrator
* @description 针对表【t_equipment(设备台账表)】的数据库操作Service实现
* @createDate 2022-10-13 11:16:24
*/
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment>
    implements EquipmentService{

    @Autowired
    private EquipmentMapper equipmentMapper;


    @Override
    public PageInfo<Equipment> queryByPage(EquipmentSearchMap map) {

        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<Equipment> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isBlank(map.getEquipmentCoding())) {
            wrapper.like("equipment_coding", map.getEquipmentCoding());
        }
        if(!StringUtils.isBlank(map.getDeviceName())){
            wrapper.like("device_name",map.getDeviceName());
        }
        if(!StringUtils.isBlank(map.getEquipmentType())){
            wrapper.eq("equipment_type",map.getEquipmentType());
        }
        if(!StringUtils.isBlank(map.getInstallationSite())){
            wrapper.like("installation_site",map.getInstallationSite());
        }
        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("purchase_date",map.getStartTime(),map.getEndTime());
        }
        PageInfo<Equipment> pageInfo = new PageInfo<>(equipmentMapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }

    @Override
    public Set<String> installLocations() {
        return equipmentMapper.installLocations();
    }
}




